package com.jjyd.crlp.controller;


import com.jjyd.crlp.model.base.ResultListModel;
import com.jjyd.crlp.model.dto.home.NewsInfoDto;
import com.jjyd.crlp.services.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户登陆
 */
@RestController
@RequestMapping("/home")
@Api(description = "用户登陆接口")
public class HomeController {

    @Autowired
    private HomeService homeService;

    /**
     * 根据数量获取新闻内容
     * @param quantity 获取的新闻数
     * @return 返回新闻内容
     */
    @GetMapping("/getNews")
    @ApiOperation(value = "获取新闻信息")
    public ResultListModel<NewsInfoDto,Object> getNews(
            @ApiParam(value = "获取的新闻的数量", required = true) @RequestParam("quantity") Integer quantity) {

        List<NewsInfoDto> news = homeService.getNews(quantity);
        return new ResultListModel<NewsInfoDto, Object>(news);
    }
}
